//
//  CYHDrawNewCell.m
//  Cat
//
//  Created by dllo on 15/11/28.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "CYHDrawNewCell.h"

@implementation CYHDrawNewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
//        @property (nonatomic, strong) UIImageView *PicImageView;
//        @property (nonatomic, strong) UIImageView *headerImageView;
//        @property (nonatomic, strong) UILabel *nameLabel;
//        @property (nonatomic, strong) UIButton *likeButton;
//        @property (nonatomic, strong) UILabel *likeLabel;
    }
    return self;
}

- (void)createView {
    self.PicImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.PicImageView];
//    self.PicImageView.backgroundColor = [UIColor redColor];
    
    self.headerImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.headerImageView];
//    self.headerImageView.backgroundColor = [UIColor yellowColor];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.nameLabel];
//    self.nameLabel.backgroundColor = [UIColor cyanColor];
    
  
    
    
    self.timeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.timeLabel];
//    self.timeLabel.backgroundColor = [UIColor greenColor];
    
    self.likeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.contentView addSubview:self.likeButton];
//    self.likeButton.backgroundColor = [UIColor greenColor];
    
    self.likeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.likeLabel];
//    self.likeLabel.backgroundColor = [UIColor yellowColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.headerImageView.layer.masksToBounds = YES;
    self.headerImageView.layer.cornerRadius = 25;
    [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(5);
        make.top.equalTo(self.contentView.mas_top).with.offset(5);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(50);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(5);
        make.left.equalTo(self.headerImageView.mas_right).with.offset(5);
        make.width.mas_equalTo(self.contentView.frame.size.width - 60);
        make.height.mas_equalTo(20);
    }];
    //    self.nameLabel.backgroundColor = [UIColor yellowColor];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.textColor = [UIColor grayColor];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).with.offset(5);
        make.left.equalTo(self.headerImageView.mas_right).with.offset(5);
        make.width.mas_equalTo(self.contentView.frame.size.width - 60);
        make.height.mas_equalTo(20);
    }];
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    
    [self.PicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).with.offset(10);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-40);
    }];
    
    [self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).with.offset(-10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-5);
    }];
    self.likeLabel.font = [UIFont systemFontOfSize:15];
    
    [self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.likeLabel.mas_left).with.offset(-10);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-5);
    }];
}

- (void)setModel:(HotModel *)model {
    self.likeLabel.text = [NSString stringWithFormat:@"%@", model.likes];
    [self.PicImageView sd_setImageWithURL:[NSURL URLWithString:model.content[@"url"]] placeholderImage:[UIImage imageNamed:@"ooopic_1445565008@2x.png"]];
    self.timeLabel.text = [NSString stringWithFormat:@"%@", [TimeTool Whattime:model.content[@"time"]]];
   
    self.nameLabel.text = @"";
    self.headerImageView.image = NULL;
    // 个人信息
    [ToolNetWorking ToolNetWorking:[NSString stringWithFormat:@"http://user.huapipi.com/userinfo/basic.do?uid=%@", model.uid] block:^(id result) {
        self.nameLabel.text = [NSString stringWithFormat:@"%@", result[@"nickname"]];
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:result[@"portrait"]] placeholderImage:[UIImage imageNamed:@"ooopic_1445565008@2x.png"]];
    }];
}

@end
